package main

import (
	"crypto/ecdsa"
	"errors"

	"github.com/ChainSafe/gossamer/lib/crypto/sr25519"
	"github.com/ethereum/go-ethereum/common/hexutil"
	"github.com/ethereum/go-ethereum/crypto"
)

// 生成以太坊密钥对
func generateEthereumKeyPair() (string, string, error) {
	privateKey, err := crypto.GenerateKey()
	if err != nil {
		return "", "", err
	}

	publicKey := privateKey.Public()
	publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey)
	if !ok {
		return "", "", errors.New("publicKey is not of type *ecdsa.PublicKey")
	}

	privateKeyBytes := crypto.FromECDSA(privateKey)
	address := crypto.PubkeyToAddress(*publicKeyECDSA).Hex()
	return address, "0x" + hexutil.Encode(privateKeyBytes)[2:], nil
}

// 生成波卡密钥对
func generatePolkadotKeyPair() (string, string, error) {
	keyPair, err := sr25519.GenerateKeypair()
	if err != nil {
		return "", "", err
	}

	return string(keyPair.Public().Address()), keyPair.Private().Hex(), nil
}
